layui.use(['form', 'table', 'layer'], function () {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        layer = layui.layer;




    $.get({
        url: "/api/department/partList", success: (resp) => {
            resp.forEach(r => {
                $("#part").append("<option value='" + r.pid + "'>" + r.pname + "</option>");
            });
        }, dataType: "json"
    });

    $("#part").on("click", () => {
        //部门id
        let pid = $('#part option:selected').val();
        console.log('选中的部门id', pid)
    });


    //监听提交
    form.on('submit(formDemo)', function (data) {
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;

    //普通图片上传
    var uploadInst = upload.render({
        elem: '#test1'
        , url: '/images/*'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        }
        , done: function (res) {
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
    })
});

